package com.ruoyi.storage.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.storage.domain.ItemDetail;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.WarehouseInventory;
import com.ruoyi.storage.service.IWarehouseInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存查询Controller
 * 
 * @author 庞一恺
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/storage/warehouseInventory")
public class WarehouseInventoryController extends BaseController
{
    @Autowired
    private IWarehouseInventoryService warehouseInventoryService;

    /**
     * 查询库存查询列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseInventory warehouseInventory)
    {
        startPage();
        List<WarehouseInventory> list = warehouseInventoryService.selectWarehouseInventoryList(warehouseInventory, SecurityUtils.getUserId());
        return getDataTable(list);
    }
    /**
     * 查看库存详情按钮
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:detail')")
    @GetMapping("/detail")
    public List<ItemDetail> detail(String batchId)
    {
       return warehouseInventoryService.selectItemDetailByBatchId(batchId);
    }

    /**
     * 导出库存查询列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:export')")
    @Log(title = "库存查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseInventory warehouseInventory)
    {
        List<WarehouseInventory> list = warehouseInventoryService.selectWarehouseInventoryList(warehouseInventory, SecurityUtils.getUserId());
        ExcelUtil<WarehouseInventory> util = new ExcelUtil<WarehouseInventory>(WarehouseInventory.class);
        util.exportExcel(response, list, "库存查询数据");
    }

    /**
     * 获取库存查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:query')")
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") String batchId)
    {
        return success(warehouseInventoryService.selectWarehouseInventoryByBatchId(batchId));
    }

    /**
     * 新增库存查询
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:add')")
    @Log(title = "库存查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseInventory warehouseInventory)
    {
        return toAjax(warehouseInventoryService.insertWarehouseInventory(warehouseInventory));
    }

    /**
     * 修改库存查询
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:edit')")
    @Log(title = "库存查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseInventory warehouseInventory)
    {
        return toAjax(warehouseInventoryService.updateWarehouseInventory(warehouseInventory));
    }

    /**
     * 删除库存查询
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseInventory:remove')")
    @Log(title = "库存查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{batchIds}")
    public AjaxResult remove(@PathVariable String[] batchIds)
    {
        return toAjax(warehouseInventoryService.deleteWarehouseInventoryByBatchIds(batchIds));
    }
}
